/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.mycompany.biblio.business;

import com.mycompany.biblio.model.User;
import javax.ejb.EJB;
import javax.ejb.Stateless;

/**
 *
 * @author thong
 */
import org.apache.shiro.SecurityUtils;

@Stateless
public class SecurityService {

    private final static String ADMIN_ROLE_NAME = "ADMIN";
    
    @EJB
    private UserDAO userDAO;
    
    public User getCurrentUser() {
        String username = (String)SecurityUtils.getSubject().getPrincipal();
        return userDAO.findByUsername(username);
    }
    
    public boolean isAdmin() {
        return SecurityUtils.getSecurityManager().hasRole(SecurityUtils.getSubject().getPrincipals(), ADMIN_ROLE_NAME);
    }
}
